<!doctype html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="icon" href="../dist/img/favicon-32x32.png" sizes="32x32" type="image/png">
    <link rel="icon" href="../dist/img/favicon-16x16.png" sizes="16x16" type="image/png">
    <meta name="keywords" content="响应式后台模板,开源免费后台模板,Bootstrap5后台管理系统模板">
    <meta name="description" content="Bootstrap-Admin基于bootstrap5的免费开源的响应式后台管理模板">
    <meta name="author" content="ajiho">
    <link rel="stylesheet" href="../plugins/bootstrap-icons/font/bootstrap-icons.css">
    <link rel="stylesheet" href="../plugins/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../dist/css/bootstrap-admin.min.css">
    <title>Bootstrap-Admin - 开源免费响应式后台管理系统模板</title>
</head>
<body>

<div class="min-vh-100 d-flex justify-content-center align-items-center py-3 bg-light">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12 col-sm-8 col-lg-6 col-xl-4 mx-auto">
                <div class="card shadow border-0 bg-white">
                    <div class="card-header bg-white border-bottom p-4 text-center">
                        <a href="javascript:" class="fs-4 text-dark text-decoration-none">
                            Bootstrap-Admin
                        </a>
                    </div>
                    <div class="card-body">
                        <form id="form" class="form">
                            <div class="mb-3">
                                <label for="username" class="form-label">账号</label>
                                <input type="text" class="form-control" id="username" name="username"
                                       placeholder="邮箱/用户名/手机号">
                            </div>
                            <div class="mb-3">
                                <label for="password" class="form-label">密码</label>
                                <input type="password" class="form-control" id="password" name="password"
                                       placeholder="请输入密码">
                            </div>
                            <div class="mb-3">
                                <label for="captcha" class="form-label">验证码</label>
                                <div class="input-group mb-3">
                                    <input type="text" class="form-control" id="captcha" name="captcha"
                                           placeholder="请输入验证码">
                                    <img src="../dist/img/captcha.png" alt="验证码" class="bsa-cursor-pointer"/>
                                </div>
                            </div>
                            <div class="d-flex align-items-center justify-content-between flex-wrap gap-3">
                                <div class="form-check">
                                    <input type="checkbox" class="form-check-input" id="exampleCheck1" name="remember"
                                           value="1">
                                    <label class="form-check-label" for="exampleCheck1">十天内免登录</label>
                                </div>
                                <button id="login-btn" type="submit" class="btn btn-primary">立即登录</button>
                            </div>
                        </form>
                    </div>

                    <div class="card-footer bg-white">
                        <div class="text-center p-2 text-muted">
                            Copyright © 2022 欲饮琵琶码上催 All right reserved.
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="../plugins/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="../dist/js/bootstrap-admin.min.js"></script>
<!--表单验证相关依赖-->
<script src="../plugins/jquery/dist/jquery.min.js"></script>
<script src="../plugins/formvalidation/js/formValidation.js"></script>
<script src="../plugins/formvalidation/js/framework/bootstrap.js"></script>
<script src="../plugins/formvalidation/js/language/zh_CN.js"></script>

<script>
    //前端表单验证
    $('#form').formValidation({
        fields: {
            username: {
                validators: {
                    notEmpty: true,
                }
            },
            password: {
                validators: {
                    notEmpty: true,
                }
            },
            captcha: {
                validators: {
                    notEmpty: true,
                }
            }
        }
    }).on('success.form.fv', function (e) {
        //阻止表单提交
        e.preventDefault();
        //得到表单对象
        let $form = $(e.target);
        let data = $form.serialize();

        alert('表单验证通过,即将发起ajax');
        //得到序列化数据
        $.ajax({
            url: "/login.php",
            method: 'POST',
            data
        }).then(function (res) {
            if (res.code === 200) {
                //登录成功
            } else {
                //登录失败
            }
        });
    });
</script>

</body>
</html>
